home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 8- transitions / source / mainframe.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  5.8 KB  |  188 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import java.util.Vector;
  5. import java.util.StringTokenizer;
  6.  
  7. import quicktime.QTException;
  8. import quicktime.QTSession;
  9. import quicktime.app.display.QTCanvas;
  10.  
  11. import quicktime.app.anim.Compositor;
  12.  
  13. /**
  14.  * QTZoo Module 7 - Switching between two compositors
  15.  * This application requires QuickTime for Java
  16.  *
  17.  * @author Levi Brown
  18.  * @author Michael Hopkins
  19.  * @author Apple Computer, Inc.
  20.  * @version 6.1 4/10/2000
  21.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  22.  *    
  23.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  24.  *                ("Apple") in consideration of your agreement to the following terms, and your
  25.  *                use, installation, modification or redistribution of this Apple software
  26.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  27.  *                please do not use, install, modify or redistribute this Apple software.
  28.  *
  29.  *                In consideration of your agreement to abide by the following terms, and subject
  30.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  31.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  32.  *                reproduce, modify and redistribute the Apple Software, with or without
  33.  *                modifications, in source and/or binary forms; provided that if you redistribute
  34.  *                the Apple Software in its entirety and without modifications, you must retain
  35.  *                this notice and the following text and disclaimers in all such redistributions of
  36.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  37.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  38.  *                Apple Software without specific prior written permission from Apple.  Except as
  39.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  40.  *                are granted by Apple herein, including but not limited to any patent rights that
  41.  *                may be infringed by your derivative works or by other works in which the Apple
  42.  *                Software may be incorporated.
  43.  *
  44.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  45.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  46.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  47.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  48.  *                COMBINATION WITH YOUR PRODUCTS.
  49.  *
  50.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  51.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  52.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  54.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  55.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  56.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57.  * 
  58.  * 
  59.  */
  60.  
  61.  
  62. public class MainFrame extends Frame
  63. {
  64.     public static final int WIDTH  = 640;
  65.     public static final int HEIGHT = 480;
  66.  
  67.     /**
  68.      * Creates the QTCanvas, loads media, and displays window contents
  69.      */
  70.     public MainFrame( String s )
  71.     {
  72.         super( s );
  73.         setResizable( false );
  74.         setBounds( 0, 0, WIDTH, HEIGHT );
  75.         
  76.         myQTCanvas = new QTCanvas( QTCanvas.kInitialSize, 0.5F, 0.5F ); // Create new QT Canvas
  77.         add( myQTCanvas );
  78.         
  79.         loadPanes( );                                                    // Load the zebra pane
  80.         
  81.         try
  82.         {
  83.             myQTCanvas.setClient (mapPane.getCompositor(), true);                //Set the canvas to display the map pane
  84.         }
  85.         catch (QTException exc)
  86.         {
  87.             exc.printStackTrace();
  88.         }                                                                    
  89.  
  90.         addWindowListener( new WindowAdapter()                             // Registers a listener for the window close box
  91.         {
  92.             public void windowClosing( WindowEvent we )
  93.             {
  94.                 QTSession.close();                                        // shut down QT and clean up
  95.                 dispose();                                                // destroy window
  96.             }
  97.             public void windowClosed( WindowEvent we )
  98.             {
  99.                 System.exit( 0 );                                        // exit to shell
  100.             }
  101.         });
  102.         
  103.         show();                                                            // Show the window and bring to front        
  104.         toFront();
  105.     }
  106.     
  107.     /**
  108.      * Loads the data displayed in each of the animal panes
  109.      */
  110.     public void loadPanes()
  111.     {
  112.         actionListener = new Action();
  113.  
  114.         mapPane = new MapPane( );
  115.         mapPane.addActionListener(actionListener);
  116.  
  117.         zebraPane = new AnimalPane( );
  118.  
  119.         zebraPane.addActionListener(actionListener);
  120.     }
  121.     
  122.     protected void transition(ZooPane fromPane, ZooPane toPane )
  123.     {
  124.         Compositor fromComp = fromPane.getCompositor();
  125.         Compositor toComp = toPane.getCompositor();
  126.         
  127.         try
  128.         {
  129.             myQTCanvas.setClient(toComp, true);
  130.             toPane.start();
  131.             fromPane.stop();
  132.         }
  133.         catch (QTException exc)
  134.         {
  135.             exc.printStackTrace();
  136.         }
  137.     }
  138.  
  139.     /**
  140.      * Responds to actions targeting the MainFrame
  141.      * Responsible for handling clicks in the animal regions in the Map Pane
  142.      */
  143.     class Action implements ActionListener
  144.     {
  145.         public void actionPerformed(ActionEvent event)
  146.         {
  147.             Object source = event.getSource();
  148.             String command = event.getActionCommand();
  149.             StringTokenizer st = new StringTokenizer(command, ";");
  150.             Vector params = new Vector();
  151.                         
  152.             while (st.hasMoreTokens())
  153.             {
  154.                 params.addElement(st.nextToken());
  155.             }
  156.  
  157.             //Minimalistic error checking...
  158.             if (params.size() < 3)
  159.             {
  160.                 System.err.println("Not enough parameters in command");
  161.                 return;
  162.             }
  163.             
  164.             //Parse our action command for pertinate info    
  165.             String area = (String)params.elementAt(0);
  166.  
  167.             if (source.equals(mapPane))
  168.             {
  169.                 zebraPane.playSound();
  170.                 transition(mapPane, zebraPane);
  171.             }
  172.             else if (source instanceof AnimalPane)
  173.             {
  174.                 if (area.equals("map"))
  175.                 {
  176.                     transition((AnimalPane)source, mapPane );
  177.                 }
  178.             }
  179.         }
  180.     }
  181.     
  182.     protected ActionListener actionListener;
  183.     protected MapPane mapPane;
  184.     protected AnimalPane zebraPane;
  185.  
  186.     protected QTCanvas myQTCanvas;
  187. }
  188.